package com.atguigu.upp.service;

import com.atguigu.upp.beans.TagInfo;
import com.atguigu.upp.beans.TaskInfo;
import com.atguigu.upp.beans.TaskTagRule;
import com.atguigu.upp.mappers.TagInfoMapper;
import com.atguigu.upp.mappers.TaskInfoMapper;
import com.atguigu.upp.mappers.TaskTagRuleMapper;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * Created by Smexy on 2022/9/9
 */
public class MysqlDBService
{

    private TagInfoMapper tagInfoMapper;
    private TaskInfoMapper taskInfoMapper;
    private TaskTagRuleMapper taskTagRuleMapper;

    public MysqlDBService(SqlSession sqlSession){

        this.taskTagRuleMapper = sqlSession.getMapper(TaskTagRuleMapper.class);
        this.tagInfoMapper = sqlSession.getMapper(TagInfoMapper.class);
        this.taskInfoMapper = sqlSession.getMapper(TaskInfoMapper.class);

    }

    public TagInfo getTagInfoByTaskId(Integer id){
        //可能有一些公司定义的业务规范 第一步... 第二步...
        if (id == null || id <= 0){
            throw new RuntimeException("参数非法!");
        }

        TagInfo tag = tagInfoMapper.getTagInfoByTaskId(id);

        return tag;

    }

    //查询今天所有要计算的标签
    public List<TagInfo> getTagInfosWithOn(){

        List<TagInfo> tags = tagInfoMapper.getTagInfoWithTaskOn();

        return tags;
    }

    //查询当前所有要执行的任务
    public List<TaskInfo> getAllTaskNeedToExecute(){

        List<TaskInfo> tasks = taskInfoMapper.getAllTaskNeedToExecute();

        return tasks;
    }

    //根据id查询某一个任务
    public TaskInfo getTaskInfoById(Integer id){
        if (id == null || id <= 0){
            throw new RuntimeException("参数非法!");
        }

        TaskInfo task = taskInfoMapper.getTaskInfoById(id);

        return task;

    }

    public List<TaskTagRule> getTaskTagRuleByTaskId(Integer taskId){
        if (taskId == null || taskId <= 0){
            throw new RuntimeException("参数非法!");
        }

        List<TaskTagRule> taskRules = taskTagRuleMapper.getTaskTagRuleByTaskId(taskId);

        return taskRules;

    }
}
